package com.yiyuan.app.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.guaike.core.mybatis.plugins.BaseDAO;
import com.yiyuan.app.entity.po.GRecordRoomWatchPO;
import com.yiyuan.app.mapper.GRecordRoomWatchMapper;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class GRecordRoomWatchDAO extends BaseDAO<GRecordRoomWatchMapper, GRecordRoomWatchPO> {


    public int deleteUserWatch(Long userId, Long roomId) {
        LambdaQueryWrapper<GRecordRoomWatchPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(GRecordRoomWatchPO::getRoomId, roomId);
        queryWrapper.eq(GRecordRoomWatchPO::getUserId, userId);
        return getBaseMapper().delete(queryWrapper);
    }

    public GRecordRoomWatchPO findUserOne(Long userId, Long roomId) {
        LambdaQueryWrapper<GRecordRoomWatchPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(GRecordRoomWatchPO::getRoomId, roomId);
        queryWrapper.eq(GRecordRoomWatchPO::getUserId, userId);
        return getBaseMapper().selectOne(queryWrapper);
    }

    public long getLookPersonCount(Long roomId) {
        LambdaQueryWrapper<GRecordRoomWatchPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(GRecordRoomWatchPO::getRoomId, roomId);
        return getBaseMapper().selectCount(queryWrapper);
    }

    public List<GRecordRoomWatchPO> getNewThreePerson(Long roomId) {
        LambdaQueryWrapper<GRecordRoomWatchPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(GRecordRoomWatchPO::getRoomId, roomId);
        queryWrapper.orderByDesc(GRecordRoomWatchPO::getId);
        queryWrapper.last("limit 0,3");
        return getBaseMapper().selectList(queryWrapper);
    }
}
